import en from "./langs/en.json";
import zh from "./langs/zh.json";
const map = {
  en,
  zh,
};

// 查询指定key i18n
export function getI18Key(lang, key) {
  if (lang === "default") {
    lang = localStorage.getItem("lang") || import.meta.env.VITE_APP_MAIN_LANG;
  }
  let path = key.split(".");
  let value = map[lang];
  if (!value) {
    return key;
  }

  for (let i = 0; i < path.length; i++) {
    value = value[path[i]];
    if (!value) {
      return key;
    }
  }
  return value;
}

/**
 * 默认语言
 * @type {UI.Lang}
 */
export const defaultLang = localStorage.getItem("lang") || import.meta.env.VITE_APP_MAIN_LANG;
